package com.zhu.function;

import com.zhu.utils.KeyWordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;


@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public  class SplitFunction extends TableFunction<Row> {

        public void eval(String str) throws IOException {
            List<String> list = null;
            try {
                list = KeyWordUtil.splitKeyword(str);
                for (String word : list) {
                    collect(Row.of(word));
                }
            }catch (IOException ioException){
                collect(Row.of(str));
                ioException.printStackTrace();
            }
        }
}

